<script setup>
import { onMounted } from "vue";
import { UnionAuth } from "@/utils/unionAuth/src/getToken.js";
import { authSzqs } from "@/api/index.js";
import { useRouter } from "vue-router";

const router = useRouter();
const hostname = window.location.href;
var unionAuth;
if (hostname.includes("//23.210.23.1:8081/")) {
  unionAuth = new UnionAuth({
    appKey: "225072369e204a1ba3e4c50515784334",
  });
}
// unionAuth = new UnionAuth({
//     appKey: "225072369e204a1ba3e4c50515784334",
//   });
onMounted(() => {
  if (hostname.includes("//23.210.23.1:8081/")) {
    if (typeof dd !== "undefined" && dd.ready) {
      unionAuth.ready().then((res) => {
        console.log(unionAuth);
      });
      setTimeout(() => {
        let signToken = unionAuth.getToken();
        authSzqs({ dcqcTk: signToken }).then((res) => {
          if (res.data.code == 200) {
            console.log(res.data.data.tokenValue, "lllllll");
            let accessToken = res.data.data.tokenValue;
            localStorage.setItem("accessToken", accessToken);
            router.replace("/");
            // const url=`http://23.210.23.1:8081/edu-dw/?dcqc-tk=${accessToken}`
            // unionAuth.redirectTo(url)
          } else {
            console.log("无权");
            router.replace("../prompt");
          }
        });
      }, 9000);
    } else {
      console.log("当前不在钉钉环境中");
    }
  }


  // if (typeof dd !== "undefined" && dd.ready) {
  //     unionAuth.ready().then((res) => {
  //       console.log(unionAuth);
  //     });
  //     setTimeout(() => {
  //       let signToken = unionAuth.getToken();
  //       authSzqs({ dcqcTk: signToken }).then((res) => {
  //         if (res.data.code == 200) {
  //           console.log(res.data.data.tokenValue, "lllllll");
  //           let accessToken = res.data.data.tokenValue;
  //           localStorage.setItem("accessToken", accessToken);
  //           router.replace("/");
  //           // const url=`http://23.210.23.1:8081/edu-dw/?dcqc-tk=${accessToken}`
  //           // unionAuth.redirectTo(url)
  //         } else {
  //           console.log("无权");
  //           router.replace("./prompt");
  //         }
  //       });
  //     }, 9000);
  //   } else {
  //     console.log("当前不在钉钉环境中");
  //   }
});
</script>

<template>
  <div class="bg">
    <router-view />
  </div>
</template>

<style scoped></style>
